package com.yxhl.zoume.core.officialcar.presenter;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.officialcar.view.CancelOfficialCarOrderView;
import com.yxhl.zoume.data.http.rest.param.officialcar.CancelOfficialCarOrderParam;
import com.yxhl.zoume.data.http.rest.response.specialcar.CancelOrderResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.car.officialcar.CancelOfficialCanOrderUseCase;

import javax.inject.Inject;

/**
 * 项目名称：Ferrari
 * Created by menggod on 16/8/23 .
 */
public class CancelOfficialCarOrderPresenter extends BasePresenter {

    private static final String TAG = "CancelOfficialCarOrderPresenter";

    @Inject
    CancelOfficialCanOrderUseCase cancelOfficialCanOrderUseCase;

    CancelOfficialCarOrderView mCancelView;

    @Inject
    public CancelOfficialCarOrderPresenter(Context context) {
        super(context);
    }


    public void cancelOrder(String orderId, String remark) {
        CancelOfficialCarOrderParam param = new CancelOfficialCarOrderParam(
                getMobile(),
                getToken(),
                orderId,
                remark
        );
        cancelOfficialCanOrderUseCase.execute(param, new ZMSubscriber<CancelOrderResponse>() {
            @Override
            public void onCompleted() {
                super.onCompleted();

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mCancelView.renderCancelCarOrderOnFailure(e.getMessage() + "请重试");
            }

            @Override
            public void onNext(CancelOrderResponse cancelOrderResponse) {
                super.onNext(cancelOrderResponse);
                if (cancelOrderResponse != null) {
                    boolean isSucc = cancelOrderResponse.isSucc();
                    if (isSucc) {
                        mCancelView.renderCancelCarOrderOnSuccess();
                    } else {
                        mCancelView.renderCancelCarOrderOnFailure(cancelOrderResponse.getResultMessage());
                    }
                }
            }
        });
    }


    @Override
    public void attachView(BaseView view) {
        mCancelView = (CancelOfficialCarOrderView) view;
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {
        cancelOfficialCanOrderUseCase.unsubscribe();
    }

}
